﻿using Microsoft.AspNet.StaticFiles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Microsoft.AspNet.Builder
{

    public static class SinoStaticFileExtensions
    {

        public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, Action<StaticFileOptions> options)
        {
            var _options = new StaticFileOptions();
            options(_options);
            return builder.UseStaticFiles(_options);
        }

        public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, IDictionary<string, string> mimeSettings)
        {
            var _options = new StaticFileOptions();
            var provider = new FileExtensionContentTypeProvider();
            foreach (var item in mimeSettings)
            {
                if (!provider.Mappings.ContainsKey(item.Key))
                {
                    provider.Mappings.Add(item.Key, item.Value);
                }
                else
                {
                    provider.Mappings[item.Key] = item.Value;
                }
            }
            _options.ContentTypeProvider = provider;
            return builder.UseStaticFiles(_options);
        }

    }

}